<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">
    </div>
    <script>
        const obj = {
            name: "kkk"
        }
        document.querySelector('#box').innerHTML = obj.name; // 初始化
        Object.defineProperty(obj, 'name', {
            get() {
                // 读取时触发
                return obj.name;
            },
            set(newVal) {
                // 修改时触发
                document.querySelector('#box').innerHTML = newVal; // 属性更新 重新渲染渲染更新页面
            }
        })
        setTimeout(() => {
            obj.name = 'bbb'
        }, 1000)
    </script>
</body>
</html>